import _ from "lodash"
import ResultSet from "@/class/ResultSet"

export const animate = (element, animateClassName) => {
	return new Promise((resolve, reject) => {
		element = _.isElement(element) ? element : undefined

		function handleAnimationEnd(event) {
			event.stopPropagation()
			element.classList.remove(animateClassName)
			resolve(`Animation ended`)
		}

		if (element) {
			element.addEventListener("animationend", handleAnimationEnd, { once: true })
			element.classList.add(animateClassName)
		} else reject(`Element is undefined`)
	})
}
